package com.example.featuresdk.view

import android.util.Log
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.layout
import kotlin.math.roundToInt
import kotlin.random.Random

@Composable
fun FloatUpAnimation(visible: Boolean = true, content: @Composable () -> Unit){

    val offset by animateFloatAsState(if(visible) 0f else 1f)
    Box(Modifier.layout { measurable, constraints ->
        val placeable = measurable.measure(constraints)
        layout(placeable.width,placeable.height){
            placeable.placeRelative( 0 ,(offset * placeable.height).roundToInt())
        }
    }) {
        content()
    }
}

@Composable
fun FloatLeftAnimation(visible: Boolean = true, content: @Composable () -> Unit){

//    Log.i("Animation2","Animation2 $visible   ${Random.nextInt()}")
    val offset by animateFloatAsState(if(visible) 0f else 1f)
    Box(Modifier.layout { measurable, constraints ->
        val placeable = measurable.measure(constraints)
        layout(placeable.width,placeable.height){
            placeable.placeRelative((offset * placeable.width).roundToInt(),0)
        }
    }) {
//        Log.i("Animation2","content() $visible   ${Random.nextInt()}")
        content()
    }
}